<template>
	<view>
		<cu-custom bgColor="bg-cyan" isBack>
			<block slot="content">input输入框</block>
		</cu-custom>
		<view class="smart-padding-wrap">
			<view class="item">可自动获取焦</view>
			<view><input class="smart-input" focus="true" placeholder="自动获取焦点"></view>
			<view class="item">右小角显示搜索</view>
			<view><input class="smart-input" confirm="search" placeholder="右小角显示搜索"></view>
			<view>同步获取输入值
				<text style="color: chocolate;">{{inputValue}}</text>
			</view>
			<view><input class="smart-input" @input="onKeyInput" placeholder="同步获取输入值"></view>
			<view>带小数点的输入</view>
			<view><input class="smart-input" type="digit" placeholder="这是一个带小数点的输入框"></view>
			<view>身份证输入</view>
			<view><input class="smart-input" type="idcard" placeholder="这是一个带身份证的输入框"></view>
			<view>带清除按钮</view>
			<view class="wrapper">
				<input class="smart-input" :value="clearinputValue" @input="clearInput" placeholder="这是一个带清除按钮处输入框">
				<text v-if="showClearIcon" @click="clearIcon" class="uni-icon">&#xe434;</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inputValue: "",
				showClearIcon: false,
				clearinputValue: ""
			}
		},
		methods: {
			onKeyInput(event) {
				console.log(event.detail.value);
				this.inputValue = event.detail.value
			},
			clearInput(event) {
				this.clearinputValue = event.detail.value;
				if (event.detail.value.length > 0) this.showClearIcon = true;
				else this.showClearIcon = false;
			},
			clearIcon(e) {
				this.clearinputValue = "";
				this.showClearIcon = false;
			}
		}
	}
</script>

<style>
	.item {
		margin-bottom: 40rpx;
	}

	.uni-icon {
		font-family: uniicons;
		font-size: 24px;
		font-weight: normal;
		font-style: normal;
		width: 24px;
		height: 24px;
		line-height: 24px;
		color: #999;
		margin-top: 5px;
	}

	.wrapper {
		/* #ifdef */
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		background-color: #faa;
	}
</style>
